#include "stdafx.h"
#include "Holders.h"

RapiStreamHolder::RapiStreamHolder(IRAPIStream *rapiStream)
{
    m_RapiStream = rapiStream;
}

RapiStreamHolder::~RapiStreamHolder()
{
    if(m_RapiStream != NULL)
        m_RapiStream->Release();
}

IRAPIStream *RapiStreamHolder::Stream()
{
    return m_RapiStream;
}

HRESULT FindHolder::FirstFile(const std::wstring &path, WIN32_FIND_DATA &fileSystemItem)
{
    HRESULT result = S_OK;

    m_FileHandle = FindFirstFile(path.c_str(), &fileSystemItem);

    if(m_FileHandle == INVALID_HANDLE_VALUE)
        result = S_FALSE;

    return result;
}

HRESULT FindHolder::NextFile(WIN32_FIND_DATA &fileSystemItem)
{
    HRESULT result = S_OK;
    int retValue = 0;

    retValue = FindNextFile(m_FileHandle, &fileSystemItem);

    if(retValue == 0)
        result = S_FALSE;
    
    return result;
}

FindHolder::~FindHolder()
{
    FindClose(m_FileHandle);
}

HKEY RegKeyHolder::Key()
{
    return m_Key;
}

HRESULT RegKeyHolder::OpenKey(HKEY preDefKey, const std::wstring &subKey)
{
    HRESULT result = S_OK;
    int retValue = 0;

    retValue = RegOpenKeyEx(preDefKey, subKey.c_str(), 0, 0, &m_Key);
    
    if(retValue != ERROR_SUCCESS)
        result = S_FALSE;

    return result;
}
RegKeyHolder::~RegKeyHolder()
{
    RegCloseKey(m_Key); 
}